package com.joyance.test_servlet.servlet;

import java.io.IOException;
import java.util.Enumeration;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


public class TestServletConfig extends HttpServlet {

    /**
     * 
     */
    private static final long serialVersionUID = 1L;


    @SuppressWarnings("rawtypes")
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // ServletConfig
        System.out.println("ServletConfig================");
        ServletConfig config = super.getServletConfig();
        // getServletName
        System.out.println("servletConfig.getServletName()=" + config.getServletName());
        // getInitParameter
        String realname = config.getInitParameter("realname");
        System.out.println("servletConfig.getInitParameter [realname=" + realname + "]");
        // getInitParameterNames
        Enumeration e = config.getInitParameterNames();
        System.out.print("servletConfig.getInitParameterNames [");
        while (e.hasMoreElements()) {
            Object name = e.nextElement();
            String value = config.getInitParameter(name.toString());
            System.out.print(name + "=" + value + ",");
        }
        System.out.print("]");
    }



}
